// e3.groovy
/*
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?
*/
def primeFactors(BigInteger n) {
    def primes = []
    def candidate = 2
    while (n > 1) {
        while (n % candidate == 0) {
            primes << candidate
            n /= candidate
        }
        candidate++
    }
    primes
}

factors = primeFactors(600851475143)
println factors
answer = factors.max()
println "The largest prime factor of the number 600851475143 is ${answer}."
